<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 150px;
            height: 150px;
            border-radius: 50%;
            background:-webkit-linear-gradient(top,skyblue,pink);
            text-align: center;
            line-height: 150px;
            margin: 24px auto;
            font-size: 50px;
            color: rgb(154, 18, 218);
        }
        p{
            display: flex;
            justify-content: center;
            margin-top:24px;
        }
        #stop{
            margin: 0 20px;
        }
    </style>
</head>
<body>
    <p>
    <button id="start">开始</button>
    <button id="stop">暂停</button>
    <button id="clear">归零</button>
    </p>
    <div></div>
    <script>
        let button = document.querySelectorAll('button');
        let div = document.querySelector('div');
        let num = 0;
        div.innerHTML = num;
        var timer = null; 
        button[0].addEventListener('click', function () {
            clearInterval(timer);
            timer = setInterval(() => {
                num++;
                div.innerHTML = num;
            }, 1000);
        });
        button[1].addEventListener('click', function () {
            clearInterval(timer);
        });
        button[2].addEventListener('click', function () {
            // clearInterval(timer); 归零后，不能自动从0开始倒计时
            num = 0;
            div.innerHTML = num;
        });
    </script>
</body>
</html>